package com.opcode.nebulamobil.base.fragments.dialogfragments;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

/**
 * Kullan�c�lara g�sterilecek olan dialoglar�n �st s�n�f�n� olu�turur.
 * @author Okan ERDO�AN
 *
 * 20 Eyl 2014
 */
public class DialogFragmentBase extends DialogFragment{

	
	public InputMethodManager inputMethodManager;
	/**
	 * Bu metod �st s�n�f taraf�ndan tetikleniyor.
	 */
	public Dialog onCreateDialog(Bundle savedInstanceState) {
		Dialog dialog = super.onCreateDialog(savedInstanceState);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setCancelable(true);
        this.inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        return dialog;
	}
	

	/**
	 * 
	 * @param viewContainerId
	 * @param selectionFragment
	 */
	public void subFragmentAddToContainer(int viewContainerId, Fragment selectionFragment){
		FragmentManager fragmentManager = getActivity().getSupportFragmentManager();		
		FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();		
		fragmentTransaction.add(viewContainerId, selectionFragment);
		fragmentTransaction.show(selectionFragment);		
		fragmentTransaction.commit();
	}
	
	/**
	 * 
	 * @param viewContainerId
	 * @param selectionFragment
	 */
	public void subFragmentAddToChildContainer(int viewContainerId, Fragment selectionFragment){
		FragmentManager fragmentManager = getChildFragmentManager();		
		FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();		
		fragmentTransaction.add(viewContainerId, selectionFragment);
		fragmentTransaction.show(selectionFragment);		
		fragmentTransaction.commit();
	}
	
	
	public void showSoftInput(EditText editText){
		editText.requestFocus();
        getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
	}
	public void hideSoftInput(){
        getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_HIDDEN);
	}
}
